<template>
  <a-card>
    <v-table
      :toolbar="true"
      bordered
      ref="table"
      :showPagination="false"
      :data="loadData"
      :tableColumn="tableColumns"
    >
      <template v-slot:buttons>
        <a-button @click="addData" icon="plus" type="primary">新建</a-button>
        <a-button @click="addData" icon="download" type="plain" style="margin-left: 12px">下载二维码标签</a-button>
        <a-button @click="showModal" icon="download" type="plain" style="margin-left: 12px">导入</a-button>
        <a-button @click="handleExportXls" icon="download" type="plain" style="margin-left: 12px">导出</a-button>
        <a-button @click="addData" icon="download" type="plain" style="margin-left: 12px">下载文件</a-button>
        <a-button @click="addData" icon="download" type="plain" style="margin-left: 12px">更多操作</a-button>
      </template>

      <template v-slot:action="{ text, row }">
         <span>
          <a-popconfirm title="是否删除" @confirm="deleteItem(row)" okText="是" cancelText="否">
            <a-icon slot="icon" type="question-circle-o" style="color: red"/>
            <a href="javascript:;" style="color: red">删除</a>
          </a-popconfirm>
        </span>
      </template>
    </v-table>
    <!-- 导入 -->
    <b-import-file
      @ok="queryPage"
      :actionUrl="actionUrl"
      ref="BImportFile"/>
  </a-card>
</template>

<script>
  import vTable from "@/components/VxeTableDemo"
  import { fetchList } from "@/api/boms/product"
  import BImportFile from "@/components/BImportFile";

  export default {
    name: "index",
    components: { vTable, BImportFile },
    data() {
      return {
        tableColumns:[
          {
            title: '序号',
            field: 'key'
          },
          {
            title: '打卡区间',
            field: 'between'
          },
          {
            title: '总人数',
            field: 'allNum'
          },
          {
            title: '已签到人数',
            field: 'signIndNum'
          },
          {
            title: '未签到人数',
            field: 'notSignInNum'
          },
          {
            title: '弘德已签到',
            field: 'hdSign'
          },
          {
            title: '弘德未签到',
            field: 'hdNotSign'
          },
          {
            title: '本部已签到',
            field: 'localSign'
          },
          {
            title: '本部未签到',
            field: 'localNotSign'
          }
        ],
        // 导入接口
        actionUrl: '',
        loadData: parameter => {
          return fetchList(
            Object.assign(parameter, this.queryParam)
          ).then(res => {
            if(res.code !== 0){
              this.$message.error(res.message)
            }
            return res.data
          })
        }
      }
    },
    methods:{
      addData() {},
      queryPage() {

      },
      // 导入
      showModal() {
        this.$refs.BImportFile.show()
      },
      handleExportXls() {
        getCtvEpt().then((response) => {
          let data = response.data
          if (!data) {
            this.$message.warning('文件下载失败')
            return
          }
          let name = decodeURI(response.headers.filename)
          let blob = new Blob([data])
          if (typeof window.navigator.msSaveBlob !== 'undefined') {
            window.navigator.msSaveBlob(blob, name)
          } else {
            let url = window.URL.createObjectURL(blob)
            let link = document.createElement('a')
            link.style.display = 'none'
            link.href = url
            link.setAttribute('download', name)
            document.body.appendChild(link)
            link.click()
            document.body.removeChild(link) //下载完成移除元素
            window.URL.revokeObjectURL(url) //释放掉blob对象
          }
        })
      }
    }
  }
</script>

<style scoped>

</style>